/*******************************************************************************
02_12: Make Table 12: Effect of wife earning more than husband on total non-market
	work for women, dropping relative earnings from 0.489 to 0.50

Replication code for "Culture and gender allocation of tasks: source country 
	characteristics and the division of non-market work among US immigrants" in
	Review of Economics of the Household

Authors: Francine Blau, Lawrence Kahn, Matthew Comey, Amanda Eng, Pamela 
	Meyerhofer, and Alexander Willen
	
Date: 10/16/2020

Description: This code generates Table 12 in the appendix of the paper. 

*******************************************************************************/

/*******************************************************************************

I. Preliminaries

*******************************************************************************/

***A. Erase existing output if necessary
cap erase "$tables/Table_12_Panel_A.xls"
cap erase "$tables/Table_12_Panel_A.txt"
cap erase "$tables/Table_12_Panel_B.xls"
cap erase "$tables/Table_12_Panel_B.txt"
cap erase "$tables/Table_12_Panel_C.xls"
cap erase "$tables/Table_12_Panel_C.txt"
cap erase "$tables/Table_12_Panel_D.xls"
cap erase "$tables/Table_12_Panel_D.txt"


***B. Set control variables
local controls age age2 hsdi scol cold RACE2 RACE3 RACE4 RACE5 

local ch_controls young_children middle_children old_children

local part_controls part_age part_age2 part_hsdi part_scol part_cold part_RACE2 part_RACE3 part_RACE4 part_RACE5

local fe i.day i.month i.year i.statefip

local income_controls logearnings logearnings2 logearnings3 sp_logearnings sp_logearnings2 sp_logearnings3 fam_logearnings

local controls_im yrsusa1 yrsusa2 cohort70_79 cohort80_89 cohort90_99 cohort00_09 cohort10_17 

local part_controls_im part_immig part_secondgen part_yrsusa1 part_yrsusa2 part_cohort70_79 part_cohort80_89 part_cohort90_99 part_cohort00_09 part_cohort10_17

local source_country GDP fertility

local parent_source_country parent_GDP_000 parent_fertility


/*******************************************************************************

II. Run Regressions

*******************************************************************************/

local maintit  "Table 12: Effect of wife earning more than husband on total non-market work for women, dropping relative earnings from 0.489 to 0.50"

**Loop through table panels
foreach panel in A B C D {
	
	**Set sample restrictions, controls, and labels
	preserve
	
	*Drop window of relative income values
	replace wifeEarnsMore = 0
	drop if relinc<=.5 & relinc>.489
	replace wifeEarnsMore = 1 if relinc > 0.5
	
	*Make sample restrictions as before
	if "`panel'" == "A" {
		di "*****Regressing All Women*****"
		
		keep if female == 1
		
		local tabtit "`maintit', Panel A. All Women"
		
		local all_controls `controls' `part_controls' `ch_controls' `income_controls' `fe'
		
		local cluster ""
		}
		
	else if "`panel'" == "B" {
		di "*****Regressing Native Women*****"
		
		keep if female == 1 & native_3rdp == 1
		
		local tabtit "`maintit', Panel B. Native Women"
		
		local all_controls `controls' `part_controls' `ch_controls' `income_controls' `fe'
		
		local cluster ""
		}
		
	else if "`panel'" == "C" {
		di "*****Regressing Immigrant Women*****"
		
		keep if female == 1 & immig == 1
		
		local tabtit "`maintit', Panel C. Immigrant Women"
		
		local all_controls `controls' `controls_im' `part_controls' `part_controls_im' `ch_controls' `income_controls' `fe'
		
		local cluster cluster(bpl)
		}
		
	else if "`panel'" == "D" {
		di "*****Regressing Second-Generation Immigrant Women*****"
		
		keep if female == 1 & secondgen == 1
		
		local tabtit "`maintit', Panel D. Second-Generation Women"
		
		local all_controls `controls' `part_controls' `part_controls_im' `ch_controls' `income_controls'   `fe'
		
		local cluster cluster(parent_bpl)
		}
		
		
	*Main regression
	reg $nmw wifeEarnsMore relinc `all_controls' [aw=wt06], robust `cluster'
	quietly sum $nmw if e(sample)==1
	outreg2 using "$tables/Table_12_Panel_`panel'.xls", keep(wifeEarnsMore) append addstat(Mean, r(mean)) label title("`tabtit'") nocons
	
	*For immigrants, add GGI and other source country controls
	if "`panel'" == "C" {
		
		reg $nmw wifeEarnsMore relinc GGI `all_controls' `source_country' [aw=wt06], robust `cluster'
		quietly sum $nmw if e(sample)==1
		outreg2 using "$tables/Table_12_Panel_`panel'.xls", keep(wifeEarnsMore GGI) append addstat(Mean, r(mean)) label title("`tabtit'") nocons
		
		reg $nmw wifeEarnsMore relinc GGI wifexGGI `all_controls' `source_country' [aw=wt06], robust `cluster'
		quietly sum $nmw if e(sample)==1
		outreg2 using "$tables/Table_12_Panel_`panel'.xls", keep(wifeEarnsMore GGI wifexGGI) append addstat(Mean, r(mean)) label title("`tabtit'") nocons
		
		}
		
	*For second-generation immigrants, add parent GGI and other source country controls
	if "`panel'" == "D" {
		
		reg $nmw wifeEarnsMore relinc parent_GGI `all_controls' `parent_source_country' [aw=wt06], robust `cluster'
		quietly sum $nmw if e(sample)==1
		outreg2 using "$tables/Table_12_Panel_`panel'.xls", keep(wifeEarnsMore parent_GGI) append addstat(Mean, r(mean)) label title("`tabtit'") nocons
		
		reg $nmw wifeEarnsMore relinc parent_GGI wifexparent_GGI `all_controls' `parent_source_country' [aw=wt06], robust `cluster'
		quietly sum $nmw if e(sample)==1
		outreg2 using "$tables/Table_12_Panel_`panel'.xls", keep(wifeEarnsMore parent_GGI wifexparent_GGI) append addstat(Mean, r(mean)) label title("`tabtit'") nocons
		
		}
		
		
	restore
	
	}
	
	
***erase text files
cap erase "$tables/Table_12_Panel_A.txt"
cap erase "$tables/Table_12_Panel_B.txt"
cap erase "$tables/Table_12_Panel_C.txt"
cap erase "$tables/Table_12_Panel_D.txt"
